<template>
    <div class="home">
        <Header/>
        <home-swiper :lists="swiperList"/>
        <home-icons :lists="iconList"/>
        <home-recommend :lists="recommendList" />
        <home-weekend :lists="weekendList" />
    </div>
</template>

<script lang="ts">
    import {Component, Vue} from 'vue-property-decorator';
    import axios from 'axios';
    import Header from '../components/home/Header.vue';
    import HomeSwiper from '../components/home/Swiper.vue';
    import HomeIcons from '../components/home/Icons.vue';
    import HomeRecommend from '../components/home/Recommend.vue';
    import HomeWeekend from '../components/home/Weekend.vue';

    @Component({
        components: {
            Header,
            HomeSwiper,
            HomeIcons,
            HomeRecommend,
            HomeWeekend,
        }
    })
    export default class Home extends Vue {
        private lastCity: string = '';
        private swiperList: [] = [];
        private recommendList: [] = [];
        private iconList: [] = [];
        private weekendList: [] = [];

        private created() {
            this.lastCity = '上海';
            this.getHomeInfo();
        }

        private getHomeInfo() {
            axios.get('/mock/index.json?city=' + this.lastCity)
                .then(this.getHomeInfoSucc)
        }

        private getHomeInfoSucc(res: any) {
            res = res.data;
            if (res.ret && res.data) {
                const data = res.data
                this.swiperList = data.swiperList
                this.iconList = data.iconList
                this.recommendList = data.recommendList
                this.weekendList = data.weekendList
            }
        }
    }
</script>
